import React, { Component } from "react";
import "../css/Board.css";
import eventEmitter from "../events";

class Board extends Component {
  constructor(props) {
    super(props);
    this.state = {
      messages: [],
    };
  }

  componentDidMount() {
    eventEmitter.addListener("sendMessageToBoard", (message) => {
      this.state.messages.push(message);
      this.setState({
        message: this.state.messages,
      });
    });
  }
  render() {
    return <div className="board_container">
        {
            this.state.messages.map((el,index)=>{
                return <div key={index} className="message">
                    <h3>{el.content}</h3>
                    <h3>{el.date}</h3>

                </div>
            })
        }
    </div>;
  }
}

export default Board;
